﻿using System;
using System.Collections.Generic;
using Core.Library;
using DataObject;
using DataObject.News;

namespace Event
{
    public partial class ListNews : System.Web.UI.Page
    {
        #region variables, constants, properties
        private const int _topHighlightList = 1;
        private const int _pageSizeList = 5;
        private int _pageIndexList;
        private const int _pageSizeOtherNews = 5;
        #endregion

        protected void Page_Load(object sender, EventArgs e)
        {
            _pageIndexList = Utils.GetIdFromRequestString(Utils.PageIndex, SettingValues.PageIndex);
            var exceptionId = new List<long>();
            if (!IsPostBack)
            {
                MetaKeyword.AddMetaTag(Page, "Tin tức | " + Const.Meta_Title, Const.Meta_Sapo);
                MetaKeyword.AddFacebookMetaTag(Page, "Tin tức | " + Const.Meta_Title, Const.Meta_Sapo, Const.SITE_URL, Const.Meta_Image);

                #region tin nổi bật trang tin tức
                {
                    var dt = NewsCache.News_GetHighlightList(
                        top: _topHighlightList);
                    this.ctrHighlight.Visible = this.ctrHighlight.DataBind(dt);
                    if(dt != null && dt.Rows.Count > 0)
                    {
                        for (int i = 0; i < dt.Rows.Count; i++)
                            exceptionId.Add(ConvertUtility.ConvertTo<long>(dt.Rows[i][Constants.Table_News.News_ID]));
                    }
                }
                #endregion

                #region list tin
                {
                    var dt = NewsCache.News_GetListPaging(_pageIndexList, _pageSizeList, exceptionId);
                    this.ctrList.Visible = this.ctrList.DataBind(dt);
                    if (dt != null && dt.Rows.Count > 0)
                    {
                        ctrPaging.LinkSite = "tin-tuc/";
                        ctrPaging.PageSize = _pageSizeList;
                        var total = NewsCache.News_Count(exceptionId);
                        ctrPaging.SumPage = (int)Math.Ceiling((decimal)total / _pageSizeList);
                        ctrPaging.Visible = ctrPaging.Padding(_pageIndexList);

                        //for (int i = 0; i < dt.Rows.Count; i++)
                        //    exceptionId.Add(ConvertUtility.ConvertTo<long>(dt.Rows[i][Constants.Table_News.News_ID]));
                    }
                }
                #endregion

                #region list other news
                {
                    var dt = NewsCache.News_GetOtherNews(_pageIndexList + 1, _pageSizeOtherNews, exceptionId);
                    this.ctrOtherNews.Visible = this.ctrOtherNews.DataBind(dt);
                }
                #endregion
            }
        }
    }
}